package com.zj.controller;

import com.zj.pojo.User;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller //1.定义bean
@RequestMapping("/user")
public class UserController {
    /*2.设置请求路径*/
    @RequestMapping("/save")
    /*3.设置当前操作返回值类型*/
    @ResponseBody
    public String save(@RequestParam("name")String username){
        System.out.println("save run ...");
        return "{'info'，'springmvc'}";
    }

    @RequestMapping("/selectUser")
    @ResponseBody
    public void selectUser(User user){
        System.out.println(user.toString());
    }
    @RequestMapping("/selectAllUser")
    @ResponseBody
    public void selectAllUser(User[] users){  //前段的key相同的name
        System.out.println(Arrays.toString(users));
    }
    @RequestMapping("/selectListUser")
    @ResponseBody
    public void selectListUser(@RequestParam List<User> users){//集合传参  //前段的key相同的name
        System.out.println(users);
    }

    //json格式
    @RequestMapping("/selectUserById")
    @ResponseBody
    public void selectUserById(@RequestBody int userId){
       System.out.println(userId);
    }

    //date格式
    @RequestMapping("/date")
    @ResponseBody
    public void date(Date date, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")Date date1){
        System.out.println(date + "-----" + date1);
    }



}
